package com.xfsg.core.log.appender;

import com.aliyun.openservices.aliyun.log.producer.Callback;
import com.aliyun.openservices.aliyun.log.producer.Result;
import com.aliyun.openservices.log.common.LogItem;
import com.xfsg.core.log.config.AliyunLogProperties;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;


/**
 * @Classname AliYunAppenderCallback
 * @Description Common Aliyun appender producer callback
 * @date 2021/12/14 15:25
 * @author ZhangYi
 */
public class AliYunAppenderCallback implements Callback {

    private final Logger logger = LoggerFactory.getLogger(AliYunAppenderCallback.class);

    private final String project;

    private final String logStore;

    private final String topic;

    private final String source;

    private final List<LogItem> logItems;

    public AliYunAppenderCallback(AliyunLogProperties config, List<LogItem> logItems) {
        super();
        this.project = config.getProject().getName();
        this.logStore = config.getProject().getLogstore();
        this.topic = config.getTopic();
        this.source = config.getSource();
        this.logItems = logItems;
    }

    @Override
    public void onCompletion(Result result) {

        if (!result.isSuccessful()) {
            logger.error("Failed to putLogs. project=" + project + " logStore=" + logStore +
                    " topic=" + topic + " source=" + source + " logItems=" + logItems, result);
        }

    }
}
